package com.synjones.ui.others;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.synjones.entry.SignPerson;
import com.synjones.idcardusb_reader.R;
import java.util.List;

public class OtherPersonAdapter extends BaseQuickAdapter<SignPerson, BaseViewHolder> {

    public OtherPersonAdapter(int layoutResId, @Nullable List<SignPerson> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, SignPerson item) {
        ImageView selectBackground = helper.getView(R.id.othersItemSelect);
        ImageView notSelectBackground = helper.getView(R.id.othersItemNotSelect);

        if (item.isSelected()){
            selectBackground.setVisibility(View.VISIBLE);
            notSelectBackground.setVisibility(View.GONE);
        }else{
            selectBackground.setVisibility(View.GONE);
            notSelectBackground.setVisibility(View.VISIBLE);
        }
        if (!TextUtils.isEmpty(item.getName())){
            helper.setText(R.id.itemInfoName, item.getName());
        }
        String documentNumber = item.getDocumentNumber();
        if (!TextUtils.isEmpty(documentNumber)){
            int docStrLength = documentNumber.length();
            if (docStrLength > 8)
                documentNumber = documentNumber.substring(0, 3)
                    + "***"
                    + documentNumber.substring(docStrLength -4, docStrLength);
            helper.setText(R.id.itemInfoIdno, documentNumber);
        }
        if (!TextUtils.isEmpty(item.getWorkPlace())){
            helper.setText(R.id.itemWorkSpace, item.getWorkPlace());
        }
        if (!TextUtils.isEmpty(item.getHotelName())){
            helper.setText(R.id.itemHotel, item.getHotelName());
        }
        if (!TextUtils.isEmpty(item.getRoomNumber())){
            helper.setText(R.id.itemRoom, item.getRoomNumber());
        }
        helper.setText(R.id.itemChecked, TextUtils.isEmpty(item.getSignTime()) ? "否" : "是");
    }
}
